﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AdminTool_ProsDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] == null)
        {
            Response.Redirect("~/Login.aspx");
            return;
        }

        int role = getRole(Session["username"].ToString(), 10);
        if (role == -1)
        {
            Response.Redirect("~/Login.aspx");
            return;
        }
        else if (role == 0)
        {
            Response.Redirect("~/Default.aspx");
            return;
        }
    }

    protected int getRole(String username, int role)
    {
        if (username == null) return -1;
        if (username == "") return -1;
        ShoppingDataContext spdt = new ShoppingDataContext();
        var Roles = from p in spdt.ACCOUNTs
                    where p.username == username
                    select p.Role;
        if (Roles.Count() <= 0) return -1;
        if (Roles.First() > role) return 0;
        return 1;
    }
}
